#ifndef __MEMEX_H__
#define __MEMEX_H__

	#define GET_U32(p)  ( ((UINT32)(*((UINT8 *)(p) + 0)) << 0) | \
					    ((UINT32)(*((UINT8 *)(p) + 1)) << 8) | \
					    ((UINT32)(*((UINT8 *)(p) + 2)) << 16) | \
					    ((UINT32)(*((UINT8 *)(p) + 3)) << 24))

	#define SET_U32(p, v)		\
	do{\
		*((UINT8 *)(p) + 0) = (((UINT32)(v)) >> 0) & 0xFF;\
		*((UINT8 *)(p) + 1) = (((UINT32)(v)) >> 8) & 0xFF;\
		*((UINT8 *)(p) + 2) = (((UINT32)(v)) >> 16) & 0xFF;\
		*((UINT8 *)(p) + 3) = (((UINT32)(v)) >> 24) & 0xFF;\
	} while (0)

	#define SWAP_U32(v)	((((UINT32)(v) & 0xFF000000ul) >> 24) | \
					    (((UINT32)(v) & 0x00FF0000ul) >> 8) | \
					    (((UINT32)(v) & 0x0000FF00ul) << 8) | \
					    (((UINT32)(v) & 0x000000FFul) << 24))


							/*
	 * 32-bit integer manipulation macros (big endian)
	 */
	#ifndef GET_UINT32_BE
	#define GET_UINT32_BE(n,b,i)                            \
	{                                                       \
	    (n) = ( (UINT32) (b)[(i)    ] << 24 )             \
	        | ( (UINT32) (b)[(i) + 1] << 16 )             \
	        | ( (UINT32) (b)[(i) + 2] <<  8 )             \
	        | ( (UINT32) (b)[(i) + 3]       );            \
	}
	#endif
	
	#ifndef PUT_UINT32_BE
	#define PUT_UINT32_BE(n,b,i)                            \
	{                                                       \
	    (b)[(i)    ] = (UINT8) ( (n) >> 24 );       \
	    (b)[(i) + 1] = (UINT8) ( (n) >> 16 );       \
	    (b)[(i) + 2] = (UINT8) ( (n) >>  8 );       \
	    (b)[(i) + 3] = (UINT8) ( (n)       );       \
	}
	#endif

	extern void reversal_data_4B(UINT8 *pData,UINT16 l_max_index);
	extern void reversal_data(unsigned char *pbData, long dwLen);

	extern unsigned int MemStrLen(unsigned char  *pD, unsigned int MaxLen);
	extern unsigned int MemIsFillBy(unsigned char  *pD, unsigned char fill, unsigned int MaxLen);

#endif
